/**
 * @file STL_ThreadPool.hpp
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 线程池
 * @version 0.0.1
 * @date 2020-07-16
 * 
 * @coryright Copyright Sci-Tech Laboratories (c) 2020
 * 
 */

#pragma once
#include <functional>

namespace STL
{
    typedef std::function<int(void)> ThreadTask;

    class ThreadPoolImpl;

    class ThreadPool
    {
    public:
        ThreadPool();
        ~ThreadPool();

        static ThreadPool *instance();

        /**
         * @brief 开启线程池
         * 
         * @param num  线程池数,默认4个
         * @return int 
         */
        int start(int num = 4);

        /**
         * @brief 向线程池塞入执行体
         * 
         * @param task 执行体
         * @return int proc不允许堵塞,返回-1,表示从线程池pop
         */
        int pushTask(const ThreadTask &task);

    private:
        ThreadPoolImpl *m_impl;
    };

} // namespace STL